// $codepro.audit.disable numericLiterals

package Model;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;


/**
 * This class generates random events which can interrupt the player during travel.
 * @author John Frederick
 * @version 1.0 11/16/2012
 */
public class Event {
	
	/** used to randomly generate a valid event */ 
	private final Random rand;
	
	/**
	 * constructs the Event. Instantiates the random generator.
	 */
	public Event(){
		rand = new Random();
	}//end constructor Event
	
	/**
	 * generates a random event and creates a package for sending to 
	 * the controller with the necessary data.
	 * 
	 * @return HashMap<String,Object> with all necessary data for 
	 * triggering the generated event. 
	 */
	public Map<String,Object> nextEvent(){
		final HashMap<String,Object> output = new HashMap<String,Object>();
		
		final int val = rand.nextInt(4); 
		int value;
		String s = "";
		
		switch(val){
		case 0:
		case 1:
		case 2:
			value = 0;
			output.put("value", value);
			break;
		case 3:
			value = rand.nextInt(6);
			value++;
			String title;
			switch(value){
			case 6:
				value -= 5;
			case 1:
				title = "Salavage Operation";
				output.put("title", title);
				TradeGood tg = null;
				switch(rand.nextInt(10)){
				case 0:
					tg = new TradeGood("Water", 0, 1, 30, rand.nextInt(5) + 1 );
					break;
				case 1:
					tg = new TradeGood("Furs", 1, 1, 250, rand.nextInt(5) + 1);
					break;
				case 2:
					tg = new TradeGood("Food", 2, 1, 105, rand.nextInt(5) + 1 );
					break;
				case 3:
					tg = new TradeGood("Ore", 3, 1, 390, rand.nextInt(5) + 1);
					break;
				case 4:
					tg = new TradeGood("Medicine", 4, 1, 510, rand.nextInt(5) + 1);
					break;
				case 5:
					tg = new TradeGood("Narcotics", 5, 1, 2625, rand.nextInt(5) + 1);
					break;
				case 6:
					tg = new TradeGood("Firearms", 6, 1, 725, rand.nextInt(5) + 1);
					break;
				case 7:
					tg = new TradeGood("Robots", 7, 1, 3950, rand.nextInt(5) + 1 );
					break;
				case 8:
					tg = new TradeGood("Machines", 8, 1, 690, rand.nextInt(5) + 1 );
					break;
				case 9:
					tg = new TradeGood("Games", 9, 1, 180, rand.nextInt(5) + 1 );
					break;
					
				default:
					break;
				}
				s = "You salvaged some supplies from a marooned ship." +
						" \n" + tg.getQuantity() + " " + tg.getName() +
						" were added to your inventory.";
				output.put("tradegood", tg);
				break;
			case 5:
				value -= 1;
			case 4:
				value -= 2;
			case 2:
				title = "Operation: Rescue Hobo";
				output.put("title", title);
				s = "You come across a space hobo on your travels. \n You give him 100 " +
						"credits out of the depths of your space-heart.";
				break;
			case 3:
				title = "Turtles All the Way Down";
				output.put("title", title);
				s = "You come across a wise sage who informs you that " +
						"the universe resides on the back of \n a giant " +
						"space-turtle. When you ask him where that turtle" +
						" resides,\n he says that it sits ontop of another" +
						" giant space-turtle. \n(You gain one point to " +
						"each of your player skills.)";
				break;
			default:
				break;
			}
			output.put("message", s);
			output.put("value", value);
			break;
		default:
			break;
		}
		return output;
	}//end method nextEvent
	
	/**
	 * toString method
	 * @return String the name of the Event
	 */
	public String toString(){
		final String str = null;
		return str;
	}
}//end method Event
